import {
  defineConfig
} from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path';
import config from './src/config/config'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  server: {
    port: 8001, // 端口
    proxy: {
      "/interface": {
        target: config.apiTarget,
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/interface/, ""),
        configure: (proxy, options) => {
          proxy.on('proxyReq', (proxyReq, req, res) => {
            const proxyURL = options.target + req.url;
            console.log('proxyURL', proxyURL);
            req.headers['x-req-proxyURL'] = proxyURL;
            res.setHeader('x-req-proxyURL', proxyURL); // 设置响应头可以看到
          });


        }
      },
      "/test": {
        target: "http://47.113.227.126:1002",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/test/, ""),
        configure: (proxy, options) => {
          proxy.on('proxyReq', (proxyReq, req, res) => {
            const proxyURL = options.target + req.url;
            console.log('proxyURL', proxyURL);
            req.headers['x-req-proxyURL'] = proxyURL;
            res.setHeader('x-req-proxyURL', proxyURL); // 设置响应头可以看到
          });


        }
      }
    }
  }
  // devServer: {
  //   port: 8080, // 端口
  //   proxy: {
  //     "/interface": {
  //       target: "http://47.113.227.126:8001/dev-api",
  //       changeOrigin: true,
  //       pathRewrite: {
  //         "^/interface": ""
  //       }
  //     },
  //   }
  // }
})